package com.yan.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yanl_ on 2018/4/20.
 */
public class EnumUtils {

    public enum ChatResult {

        SUCCESS(0000,"SCUESS"),
        FAIL(1011,"FAIL");

        private int resultCode;

        private String resultMsg;

        public int getResultCode() {
            return resultCode;
        }

        public void setResultCode(int resultCode) {
            this.resultCode = resultCode;
        }

        public String getResultMsg() {
            return resultMsg;
        }

        public void setResultMsg(String resultMsg) {
            this.resultMsg = resultMsg;
        }

        ChatResult(int resultCode, String resultMsg) {
            this.resultCode = resultCode;
            this.resultMsg = resultMsg;
        }

        private static ChatResult getChatResult(int resultCode) {
            for (ChatResult result : ChatResult.values()) {
                if (resultCode == result.getResultCode()) {
                    return result;
                }
            }
            return null;
        }
    }


    public enum ChatType {

        BASKETBALL("basketball"), FOOTBALL("football"), PUBLIC("public"), SNOOKER("snooker"), TENNIS(
                "tennis"), CHAT_USER_INFO("mobile:user:login:{0}");

        ChatType(String type) {
            this.type = type;
        }

        private String type;

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        private static final Map<String, ChatType> map = new HashMap<String, ChatType>();

        static {
            for (ChatType chatType : values()) {
                map.put(chatType.type, chatType);
            }
        }

        public static ChatType fromString(String type) {
            return map.get(type);
        }


    }

    public static void main(String args[]) {


        ChatResult result = ChatResult.getChatResult(0000);
        if (result != null) {
            System.out.println(result.name() + "   " + result.getResultCode() + " " + result.getResultMsg());
            result.setResultCode(404);
            result.setResultMsg("not found");
            System.out.println(";;;;;" + result.getResultCode() + " " + result.getResultMsg() + " " + result.name() + " ");
        }


        ChatResult chatResult = ChatResult.valueOf("SUCCESS");

        System.out.println("======" + chatResult.getResultCode());


    }
}
